﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DomMgmtSystem.View
{
    public partial class OutHSSJTGList : System.Web.UI.Page
    {
        string sqlWhere = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                GetPage();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            sqlWhere = " 1=1 ";
            if (ddlNTGLX.SelectedValue != "")
                sqlWhere += " and NTGLX=" + ddlNTGLX.SelectedValue;
            if (txtCSQBH.Text.Trim() != "")
                sqlWhere += " and CSQBH='" + txtCSQBH.Text.Trim() + "'";
            ListDataBind();
        }
        /*分页*/
        public void GetPage()
        {
            /*求出总记录数*/
            int c = DataAccess.TB_HSSJTG.GetCount(sqlWhere);
            /*判断当前页面是否为0*/

            /*显示设置*/
            AspNetPager1.AlwaysShow = true;
            /*每页显示数量*/
            AspNetPager1.PageSize = 10;
            /*记录总页数*/
            AspNetPager1.RecordCount = c;
            /*绑定数据源*/
            ListDataBind();
            if (c > 0)
            {
                //dv1.Visible = false;
                Repeater1.Visible = true;
            }
            else
            {
                //dv1.Visible = true;
                Repeater1.Visible = false;
            }
        }

        /*分页*/
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            ListDataBind();
        }
        /*分页*/
        public void ListDataBind()
        {
            Repeater1.DataSource = DataAccess.TB_HSSJTG.GetList(sqlWhere, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize);
            Repeater1.DataBind();
        }
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                decimal baseID = Convert.ToDecimal(e.CommandArgument.ToString());
                DataAccess.TB_HSSJTG.Delete(baseID);
                this.Alert("删除成功！");
                ListDataBind();
            }
        }
    }
}